from sample.common.base_page import BasePage
from sample.util.ddddocr_util import VerificationCodeOCR


class ManagerLoginPage(BasePage):
    URL = '/#/login'

    def login_manager(self, user, password):
        self.fill_input('ManagerLogin.LoginInput', user)
        self.fill_input('ManagerLogin.PasswordInput', password)
        for i in range(3):
            img_bytes = self.get_locator('ManagerLogin.VerificationCodeImage').screenshot()
            vocr = VerificationCodeOCR()
            text = vocr.get_verification_code(img_bytes)
            self.fill_input('ManagerLogin.VerificationCodeInput', text)
            self.click_element('ManagerLogin.LoginBtn')
            if not self.is_element_exist('ManagerLogin.LoginBtn'):
                break

    def logout(self):
        pass
